﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApp55.Models;

namespace WpfApp55
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        User user = new ();

        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = user;
        }

        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            //传统方式，使用业务逻辑进行验证
            //string userName = TbUserName.Text;
            //if (string.IsNullOrEmpty(userName))
            //{
            //    MessageBox.Show("User Name is Null!");
            //}

            //希望获得错误列表，
        }

        private void Grid_Error(object sender, ValidationErrorEventArgs e)
        {
            //NotifyOnValidationError必须是true才会触发此错误事件
            if (e.Action == ValidationErrorEventAction.Added)
            {
                MessageBox.Show(e.Error.ErrorContent.ToString());
            }
        }

        private void TbUserName_Error(object sender, ValidationErrorEventArgs e)
        {

        }
    }
}